package cn.blnp.net.flowable.listen.task.listener;

import lombok.extern.slf4j.Slf4j;
import org.flowable.common.engine.api.delegate.Expression;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.engine.impl.context.Context;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.task.service.delegate.DelegateTask;
import org.springframework.stereotype.Component;

/**
 * <h3></h3>
 *
 * @author <a href="mailto:blnp.yibin@qq.com">lyb</a>
 * @version 1.0
 * @since 2025/5/21 13:52
 */
@Slf4j
@Component
public class MyTaskListener1 implements TaskListener {
    private Expression fixedValue;
    private Expression dynamicValue;

    @Override
    public void notify(DelegateTask delegateTask) {
        //获取任务节点定义key
        String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
        //获取事件名称
        String eventName = delegateTask.getEventName();
        log.info("（{}）通过class指定的监听器：用户任务{}的{}事件触发", delegateTask.getEventName() , taskDefinitionKey, eventName);
        ExecutionEntity execution = Context.getProcessEngineConfiguration()
                .getExecutionEntityManager().findById(delegateTask.getExecutionId());
        log.info("fixedValue属性值为：{}", fixedValue.getValue(execution));
        log.info("dynamicValue属性值为：{}", dynamicValue.getValue(execution));
    }
}
